<template>
	<div class="zhengtuojianhuo">
		<van-nav-bar :fixed="true" class="navBar" title="采购退货" left-arrow @click-left="$router.go(-1)"></van-nav-bar>



    <!-- 商品编码选择 -->
		<div class="goodsFromWarp">
				<div class="goodsInputWarp">
						<div class="goodsInputLabel">
							<div class="goodsInputBorder"></div>
							<div class="skuName">商品编码：</div>
						</div>

						<van-field
							 class="skuInput"
							 clearable
							 v-model="editForm.itemid"
							 placeholder="请填写商品编码"
							 @keyup="onEnter($event,do_inputspbar)"
						 />
				</div>
		</div>

				<div class="goodsFromWarp" >


						<div class="goodsInputWarp">
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">退货单：</div>
								</div>


								<div class="skuNoInput">
									{{skuRow.bill>''?skuRow.bill:'无返厂退货信息'}}
								</div>
						</div>


						<div class="goodsInputWarp">
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">商品：</div>
								</div>


								<div class="skuNoInput">
									{{skuRow.itemid}} {{skuRow.itemid>''?'-':''}}{{skuRow.itemsname}}
								</div>
						</div>





						<div class="goodsInputWarp">
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">{{skuRow.bill == ''|| skuRow.bill == null ?'主供应商':'供应商'}}</div>
								</div>


								<div class="skuNoInput">
									{{skuRow.vendorid}} {{skuRow.vendorid>''?'-':''}}   {{skuRow.vensname}}
								</div>
						</div>

						<div class="goodsInputWarp" v-if="skuRow.bill >'' " >
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">{{skuRow.bill == ''|| skuRow.bill == null ?'返厂位':'仓位'}}</div>
								</div>


								<div class="skuNoInput">
										{{skuRow.venename>''?skuRow.venename:'无'}}
								</div>
						</div>


						<div class="goodsInputWarp" v-if="skuRow.bill >'' " >
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">主供应商：</div>
								</div>


								<div class="skuNoInput">
										{{skuRow.i6_vendorid}} {{skuRow.i6_vendorid>''?'-':''}} {{skuRow.i6_vensname}}
								</div>
						</div>


						<div class="goodsInputWarp" v-if="skuRow.bill >'' " >
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">返厂位：</div>
								</div>


								<div class="skuNoInput">
										{{skuRow.i6_venename}}
								</div>
						</div>
















						<div class="goodsInputWarp">
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">默认仓位：</div>
								</div>

								<van-field
									 class="skuInput"
									 clearable
									 v-model="editForm.jhrq"
									 @keyup="onEnter($event,do_inputspbarCangWei)"
									 placeholder="请填写默认仓位"
								 />
						</div>
				</div>



		<div class="skuBtn">
			<van-button type="info" :disabled="isdisabled" @click="lingquBtn()">领取任务</van-button>
			<van-button type="info" :disabled="isdisabled" @click="saveGoodsBtn()"  v-if="skuRow.bill >'' "  >确认</van-button>
		</div>

		<van-dialog v-model="carMessageIsShow" title="提示" show-cancel-button @confirm = "_getSaveTuiHuoClick()" confirmButtonColor="#1989fa">
			<div style="width: 100%;display: flex;flex-direction: column;align-items: center;margin-top: 8px;">
				<div>
					<p class="messageConTitle">是否将供应商 {{skuRow.vendorid}}</p>
					<p class="messageConTitle">位置指定为:{{editForm.jhrq}}</p>
					<p class="messageConTitle" style="margin-bottom: 10px;">注意,一个供应商只能有一个位置!</p>
				</div>
			</div>
		</van-dialog>

	</div>
</template>

<script>

export default {
  name: 'caigoutuihuo',
  data() {
    return {
			editForm:{
				itemid:'', // 70618574
				jhrq:'',
			},
			skuRow:{
				bill: "",
				i6_vendorid: "",
				i6_venename: '',
				i6_vensname: "",
				itemid: "",
				itemsname: "",
				pack: "",
				posin: "",
				qty: "",
				status: "",
				storeid: "",
				unit: "",
				vendorid: "",
				venename: '',
				vensname: "",
			},
			isdisabled:false,
			carMessageIsShow:false,
		};
  },
	computed: {
	   ryuser: function(){
	     return this.GWO(true).gUSER;
	   }
	},
  methods: {
		do_inputspbar(pmtxt){
			this.editForm.itemid = pmtxt
			this.lingquBtn()
		},
		lingquBtn(){
			var _self = this;
			var ldemodata = [{retval:0, errmsg:'返回数据集'},]
			this.MYPOST({
				'method':'dgate',
				'pname':'f_wmsa_y_shouhuo',
				'i':this.FNULLE([
				'opmode','Y_CGTH_qrybill',
				'czyid',this.ryuser.operatorid,
				'kqid', this.ryuser.kqid,
				'itemid',this.editForm.itemid,
				])
				},'采购退货领取任务',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
				if(ret_iserr){ //传入的true参数,理论上不会有此回调了
					_self.$toast.fail('查询失败')
					_self.$store.commit('hideLoading');
				}else{
					var rtn_json_obj = null;
					_self.$store.commit('hideLoading');
					if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
					}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
					}
					_self.lingquData = rtn_json_obj
					console.log("采购退货领取任务")
					console.log(rtn_json_obj)
					if(_self.lingquData.length > 0){
						_self.skuRow  = rtn_json_obj[0]
					}else{
						_self.$toast.fail('暂无获取商品详情')
					}
				}
			});
		},
		do_inputspbarCangWei(pmtxt){
			console.log(pmtxt)  //扫描枪获取的参数
			this.editForm.jhrq = pmtxt
			this.saveGoodsBtn()
		},
		saveGoodsBtn(){
			if(this.skuRow.venename >''){
				this.$dialog.alert({
					title: '提示',
					message:'供应商'+ this.skuRow.vendorid +'已经指定为位置:' + this.skuRow.venename + ',无需修改!',
					confirmButtonColor:'#1989fa',
				})
			}else{
				if(this.editForm.jhrq >''){
					this.carMessageIsShow = true
				}else{
						this.$toast.fail('请填写默认仓位')
				}
			}
		},
		_getSaveTuiHuoClick(){
			var _self = this;
			var ldemodata = [{retval:0, errmsg:'返回数据集'},]
			this.MYPOST({
				'method':'dgate',
				'pname':'f_wmsa_y_shouhuo',
				'i':this.FNULLE([
				'opmode','Y_CGTH_XGjhrq',
				'czyid',this.ryuser.operatorid,
				'kqid', this.ryuser.kqid,
				'vendorid',this.skuRow.vendorid,
				'venename',this.skuRow.venename,
				'jhrq',this.editForm.jhrq,
				])
				},'保存采购退货',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
				if(ret_iserr){ //传入的true参数,理论上不会有此回调了
					_self.$toast.fail('查询失败')
					_self.$store.commit('hideLoading');
				}else{
					var rtn_json_obj = null;
					_self.$store.commit('hideLoading');
					if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
					}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
					}
					_self.lingquData = rtn_json_obj
					console.log("保存采购退货")
					if(rtn_json_obj[0].ret_ret == '0'){
						_self.$toast.fail(rtn_json_obj[0].ret_mess)
						_self.editForm.itemid = ''
						_self.editForm.jhrq = ''
						_self.skuRow = {
							bill: "",
							i6_vendorid: "",
							i6_venename: '',
							i6_vensname: "",
							itemid: "",
							itemsname: "",
							pack: "",
							posin: "",
							qty: "",
							status: "",
							storeid: "",
							unit: "",
							vendorid: "",
							venename: '',
							vensname: "",
						}
					}else{
						_self.$toast.fail(rtn_json_obj[0].ret_mess)
					}
				}
			});
		},
  },
  mounted() {

  },
	components: {

	},
};
</script>

<style lang="scss" scoped>
	// 引入公共样式
	@import '@/assets/css/base.scss';
	@import '@/assets/css/input.scss';
	div.zhengtuojianhuo{
		padding-top: 50px;
	}

	.messageConTitle{
		margin-top: 10px;
		margin-bottom: 10px;
		font-weight: bold;
		font-size: 20px;
	}

</style>
